// Copyright 2024 openGemini Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OPENGEMINI_IMPL_ERRORCODE_HPP
#define OPENGEMINI_IMPL_ERRORCODE_HPP

#include "opengemini/Error.hpp"

#include <system_error>

namespace std {

template<>
struct is_error_code_enum<opengemini::errc::LogicErrors> :
    public std::true_type { };

template<>
struct is_error_code_enum<opengemini::errc::ServerErrors> :
    public std::true_type { };

template<>
struct is_error_code_enum<opengemini::errc::RuntimeErrors> :
    public std::true_type { };

} // namespace std

namespace opengemini::errc {

std::error_code make_error_code(LogicErrors error);
std::error_code make_error_code(ServerErrors error);
std::error_code make_error_code(RuntimeErrors error);

} // namespace opengemini::errc

namespace opengemini::errc::impl {

class LogicCategory : public std::error_category {
public:
    static const LogicCategory& Instance();
    const char*                 name() const noexcept override;
    std::string                 message(int value) const override;
};

class ServerCategory : public std::error_category {
public:
    static const ServerCategory& Instance();
    const char*                  name() const noexcept override;
    std::string                  message(int value) const override;
};

class RuntimeCategory : public std::error_category {
public:
    static const RuntimeCategory& Instance();
    const char*                   name() const noexcept override;
    std::string                   message(int value) const override;
};

} // namespace opengemini::errc::impl

#ifndef OPENGEMINI_SEPARATE_COMPILATION
#    include "opengemini/impl/ErrorCode.cpp"
#endif // !OPENGEMINI_SEPARATE_COMPILATION

#endif // !OPENGEMINI_IMPL_ERRORCODE_HPP
